<template>
  <el-dialog title="流程详情" :visible="visible" @close="close()">
    <el-form>
      <vue-json-editor class="history-json-view" v-model="variables" :expandedOnStart="true" :show-btns="false" :modes="['view']" mode="view" lang="zh">
      </vue-json-editor>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close()">关 闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import vueJsonEditor from 'vue-json-editor'
  import access from '../api/access.js'

  export default {
    data() {
      return {
        variables: []
      }
    },
    props: {
      visible: {
        type: Boolean,
        default: false
      },
      processInstanceId: {
        type: String,
        default: null
      }
    },
    components: {
      vueJsonEditor
    },
    watch: {
      visible(value, old) {
        if (value) {
          access.processVariables(this.processInstanceId).then(res => {
            this.variables = res.data || {}
          })
        }
      }
    },
    methods: {
      close() {
        this.$emit('onClose')
      }
    }
  }
</script>

<style>
  .history-json-view .jsoneditor {
    min-height: 200px;
  }
</style>
